package custom_sorting;

import java.util.Comparator;

public class ValueObject implements Comparable<ValueObject>,
		Comparator<ValueObject> {

	String name;
	int jntu_no;
	public Jntu_no_Comparator jc = new Jntu_no_Comparator();

	public class NameComparator implements Comparator<ValueObject> {

		@Override
		public int compare(ValueObject o1, ValueObject o2) {

			return o1.getName().compareTo(o2.getName());
		}

	}

	public class Jntu_no_Comparator implements Comparator<ValueObject> {

		@Override
		public int compare(ValueObject o1, ValueObject o2) {
			System.out.println("Custom Comparator inner class. ");
			return o1.getJntu_no() - o2.getJntu_no();
		}

	}

	public ValueObject(String name, int value) {
		super();
		this.name = name;
		this.jntu_no = value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getJntu_no() {
		return jntu_no;
	}

	public void setJntu_no(int jntu_no) {
		this.jntu_no = jntu_no;
	}

	@Override
	public int compareTo(ValueObject o) {
		System.out.println("Valueobject Comparable.compareTo() ");
		return -this.getJntu_no() + o.getJntu_no(); // Descending order
	}

	@Override
	public int compare(ValueObject o1, ValueObject o2) {
		System.out.println("ValueObject Comparator.compare() ");
		return o1.jntu_no - o2.jntu_no; // Ascending order
	}

	@Override
	public boolean equals(Object obj) {
		ValueObject o = (ValueObject) obj;
		return this.jntu_no == o.jntu_no;
	}

}
